package com.dpteam.enums;

/**
 * Created with IntelliJ IDEA.
 * User: luolei
 * Date: 2016/1/8
 * Time: 14:12
 * 性别枚举
 */
public enum Gender {

    UNKNOW(0, "未知"),

    MAN(1, "男"),

    WOMAN(2, "女")

    ;
    private int code;

    private String note;

    Gender(int code, String note) {
        this.code = code;
        this.note = note;
    }

    public int getCode() {
        return code;
    }

    public String getNote() {
        return note;
    }

    /**
     * 通过0，1，2得到性别
     * @param code
     * @return
     */
    public static Gender get(int code) {
        Gender[] genders = Gender.values();
        for (Gender gender : genders) {
            if (code == gender.getCode()) {
                return gender;
            }
        }
        return Gender.UNKNOW;
    }

    /**
     * 通过男，女，未知， 得到性别
     * @param note
     * @return
     */
    public static Gender get(String note) {
        Gender[] genders = Gender.values();
        for (Gender gender : genders) {
            if (note.equals(gender.getNote())) {
                return gender;
            }
        }
        return Gender.UNKNOW;
    }
}
